function fun_chaotic_fractal_tree;
% Chaotic Fractal Tree
% reference:
% http://www.kirupa.com/developer/actionscript/chaos_fractal.htm
%
% ??????
% ?? @ 2005-08-09 14:43
% ??????
% http://www.kirupa.com/developer/actionscript/chaos_fractal.htm
% ?????????: 

% Constants:
max_sub_branch = 4;
max_sub_angle=3*pi/4 ;
max_size=6;
branch_length=50;

% function call

hold on
makeBranch(200,300,branch_length,pi/2,max_size);
title('please double click the mouse and redraw')
set(gcf,'ButtonDownFcn',['t=get(gcf,''SelectionType'');',...
   'if t(1)==''o'';close;',...
   'ChaoticFractalTree;end'])
%% Function
function makeBranch (start_x,start_y,leng,angl,siz);
% Constants:
max_sub_branch = 4;
max_sub_angle=3*pi/4 ;
branch_length=50;
if siz>0;
   z=start_x+start_y*i;
   z_end=z+leng*exp(i*angl);
   plot([z,z_end],'linewidth',siz);
   sub_branch=rand*(max_sub_branch-1)+2;
   branch_length_dimin=.5+rand/2;
   end_x=real(z_end);
   end_y=imag(z_end);
   for k=0:sub_branch;
       newLength=leng*branch_length_dimin;
       newAngle =angl+rand*max_sub_angle-max_sub_angle/2;
       newSize=siz-1;
       makeBranch(end_x,end_y,newLength,newAngle,newSize);
   end
end 